﻿<script>
	<#if batchEditProjectList??>
	$(function(){
		<#if batchEditProjectList?size gt 0>
		sumTotalCost();
		sumPlanCost();
		</#if>
	});
	<#else>
	$(function(){
	$('#implCompanyStringsId').change(function(){
			$('input','.planprojectfee').each(function(){
				$(this).rules("remove");
			});
    	$(".planprojectfee").remove();
    	$('#planprojectfee').hide();
    	var names = document.getElementById('implCompanyStringsId').value;
    	var ids = document.getElementById('implCompanyStrings').value;
    	var before = $('#planprojectfee');
    	if(names!='') {
    		var nameArray = names.split(",");
    		var idArray = ids.split(",");
    		if(nameArray.length==1) {
    			var id = ids;
    			var tr = document.createElement("tr");
		    	$(tr).attr("class","listviewTR planprojectfee");
					var html = "<td class=\"listviewTD\" align=\"right\"><span class=\"placeholder fontRed\">*</span>计划总费用:</td>";
					html += "<td class=\"listviewContent\">";
					html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" value=\"\" id=\"totalCost"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].totalCost\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"1\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"计划总费用\"}' datarule=\"number\" >&nbsp;万元";
					html += "</td>";
					html += "<td class=\"listviewTD\" align=\"right\">当年计划安排费用:</td>";
					html += "<td class=\"listviewContent\">";
					html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" value=\"\" id=\"planCostCurrentYear"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].planCostCurrentYear\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"0\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"当年计划安排费用\"}' datarule=\"number\">&nbsp;万元";
					html += "</td>";
					html += "<td class=\"listviewTD\" align=\"right\">已拨付费用:</td>";
					html += "<td class=\"listviewContent\">";
					html += "0&nbsp;&nbsp;万元";
					html += "</td>";
		    	$(tr).html(html);
		    	$(tr).insertAfter($('#planprojectfee'));
		    	validatorForm();
		    	var optionRule10 = {};
					var optionRuleMessages10 = {};        
		    	optionRule10["messages"] = optionRuleMessages10;
		      optionRule10["compareLessNumber"] = "#totalCost"+id;				
		      optionRuleMessages10["compareLessNumber"] = "当年计划安排费用应该小于等于计划总费用！"; 
			    $("#planCostCurrentYear"+id).rules("add", optionRule10);
    		} else {
    			$('#planprojectfee').show();
	    		for(var i=0;i<nameArray.length;i++) {
	    			var name = nameArray[i];
	    			if(name!='') {
	    				var tr = document.createElement("tr");
				    	$(tr).attr("class","listviewTR planprojectfee");
				    	var html = "<td class=\"listviewTD\" align=\"center\">"+name+"</td>";
				    	html += "<td class=\"listviewContent\" ><input type=\"text\" onblur=\"sumTotalCost()\"  datarule=\"number\"    datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"1\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\""+name+"计划总费用\"}'    onblur=\"this.value=this.value.trim()\" id=totalCost"+idArray[i]+" name=\"fieldMap['planProjectMap'].planProjectMap['"+idArray[i]+"'].totalCost\" value=\"\" class=\"text totalCostText\" style=\"width:100px;\" ></input></td>";
				    	html += "<td class=\"listviewTD\" ><input type=\"text\" onblur=\"sumPlanCost()\"  datarule=\"number\"    datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"0\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\""+name+"当年计划安排费用\"}'    onblur=\"this.value=this.value.trim()\" id=planCostCurrentYear"+idArray[i]+" name=\"fieldMap['planProjectMap'].planProjectMap['"+idArray[i]+"'].planCostCurrentYear\" value=\"\" class=\"text planCostText\" style=\"width:100px;\" ></input></td>";
				    	html += "<td class=\"listviewContent\" colspan=\"3\">0</td>";
				    	$(tr).html(html);
				    	$(tr).insertAfter(before);
				    	before = $(tr);
	    			}
	    		}
	    		var sumTr = document.createElement("tr");
		    	$(sumTr).attr("class","listviewTR planprojectfee");
		    	var sumHtml = "<td class=\"listviewTD\" align=\"center\">合计</td>";
		    	sumHtml += "<td class=\"listviewContent\" ><label id=\"totalCostSum\">0</label></td>";
		    	sumHtml += "<td class=\"listviewTD\" ><label id=\"planCostSum\">0</label></td>";
		    	sumHtml += "<td class=\"listviewContent\" colspan=\"3\">0</td>";
		    	$(sumTr).html(sumHtml);
		    	$(sumTr).insertAfter(before);
	    		validatorForm();
	    		for(var i=0;i<nameArray.length;i++) {
	    			var name = nameArray[i];
	    			if(name!='') {
				    	var optionRule10 = {};
							var optionRuleMessages10 = {};        
				    	optionRule10["messages"] = optionRuleMessages10;
				      optionRule10["compareLessNumber"] = "#totalCost"+idArray[i];				
				      optionRuleMessages10["compareLessNumber"] = name+"当年计划安排费用应该小于等于"+name+"计划总费用！"; 
					    $("#planCostCurrentYear"+idArray[i]).rules("add", optionRule10);
	    			}
	    		}
    		}
    	}
    });
    
    if(document.getElementById('implCompanyStringsId') && document.getElementById('implCompanyStringsId').value!='' && document.getElementById('implCompanyStrings') && document.getElementById('implCompanyStrings').value!='') {
    	var name= document.getElementById('implCompanyStringsId').value;
    	var id = document.getElementById('implCompanyStrings').value;
    	var tr = document.createElement("tr");
    	$(tr).attr("class","listviewTR planprojectfee");
			var html = "<td class=\"listviewTD\" align=\"right\"><span class=\"placeholder fontRed\">*</span>计划总费用:</td>";
			html += "<td class=\"listviewContent\">";
			html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" value=\"\" id=\"totalCost"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].totalCost\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"1\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"计划总费用\"}' datarule=\"number\" >&nbsp;万元";
			html += "</td>";
			html += "<td class=\"listviewTD\" align=\"right\">当年计划安排费用:</td>";
			html += "<td class=\"listviewContent\">";
			html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" value=\"\" id=\"planCostCurrentYear"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].planCostCurrentYear\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"0\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"当年计划安排费用\"}' datarule=\"number\">&nbsp;万元";
			html += "</td>";
			html += "<td class=\"listviewTD\" align=\"right\">已拨付费用:</td>";
			html += "<td class=\"listviewContent\">";
			html += "0&nbsp;&nbsp;万元";
			html += "</td>";
    	$(tr).html(html);
    	$(tr).insertAfter($('#planprojectfee'));
    	validatorForm();
    	var optionRule10 = {};
			var optionRuleMessages10 = {};        
    	optionRule10["messages"] = optionRuleMessages10;
      optionRule10["compareLessNumber"] = "#totalCost"+id;				
      optionRuleMessages10["compareLessNumber"] = "当年计划安排费用应该小于等于计划总费用！"; 
	    $("#planCostCurrentYear"+id).rules("add", optionRule10);
	    if(id!='') {
	    	restorePlanProjectFee();
	    }
    }
    
	});
	
	function restorePlanProjectFee() {
		var planProjectMap = {};
		<#if businessInstanceField.instance?? && businessInstanceField.instance.fieldMap?? && businessInstanceField.instance.fieldMap['planProjectMap']?? && businessInstanceField.instance.fieldMap['planProjectMap'].planProjectMap??>
		<#list businessInstanceField.instance.fieldMap['planProjectMap'].planProjectMap?keys as key>
		<#assign planProject=businessInstanceField.instance.fieldMap['planProjectMap'].planProjectMap[key]>
		planProjectMap['${key}']={};
		planProjectMap['${key}']['totalCost']='<#if planProject.totalCost??>${planProject.totalCost?c}</#if>';
		planProjectMap['${key}']['planCostCurrentYear']='<#if planProject.planCostCurrentYear??>${planProject.planCostCurrentYear}</#if>';
		</#list> 
		</#if>
		$('input','.planprojectfee').each(function(){
			$(this).rules("remove");
		});
		$(".planprojectfee").remove();
    	$('#planprojectfee').hide();
    	var names = document.getElementById('implCompanyStringsId').value;
    	var ids = document.getElementById('implCompanyStrings').value;
    	var before = $('#planprojectfee');
    	if(names!='') {
    		var nameArray = names.split(",");
    		var idArray = ids.split(",");
    		if(nameArray.length==1) {
    			var id = ids;
    			var tr = document.createElement("tr");
		    	$(tr).attr("class","listviewTR planprojectfee");
					var html = "<td class=\"listviewTD\" align=\"right\"><span class=\"placeholder fontRed\">*</span>计划总费用:</td>";
					html += "<td class=\"listviewContent\">";
					if(planProjectMap[id]) {
    				html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" id=\"totalCost"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].totalCost\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"1\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"计划总费用\"}' value=\""+planProjectMap[id]['totalCost']+"\" datarule=\"number\" >&nbsp;万元";
    			} else {
    				html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" id=\"totalCost"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].totalCost\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"1\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"计划总费用\"}' value=\""+""+"\" datarule=\"number\" >&nbsp;万元";
    			}
					html += "</td>";
					html += "<td class=\"listviewTD\" align=\"right\">当年计划安排费用:</td>";
					html += "<td class=\"listviewContent\">";
					if(planProjectMap[id]) {
						html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" id=\"planCostCurrentYear"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].planCostCurrentYear\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"0\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"当年计划安排费用\"}' value=\""+planProjectMap[id]['planCostCurrentYear']+"\" datarule=\"number\">&nbsp;万元";
					} else {
						html += "<input class=\"text\" type=\"text\" style=\"width:130px;\" id=\"planCostCurrentYear"+id+"\" name=\"fieldMap['planProjectMap'].planProjectMap['"+id+"'].planCostCurrentYear\" datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"0\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\"当年计划安排费用\"}' value=\""+""+"\" datarule=\"number\">&nbsp;万元";
					}
					html += "</td>";
					html += "<td class=\"listviewTD\" align=\"right\">已拨付费用:</td>";
					html += "<td class=\"listviewContent\">";
					html += "0&nbsp;&nbsp;万元";
					html += "</td>";
		    	$(tr).html(html);
		    	$(tr).insertAfter($('#planprojectfee'));
		    	validatorForm();
		    	var optionRule10 = {};
					var optionRuleMessages10 = {};        
		    	optionRule10["messages"] = optionRuleMessages10;
		      optionRule10["compareLessNumber"] = "#totalCost"+id;				
		      optionRuleMessages10["compareLessNumber"] = "当年计划安排费用应该小于等于计划总费用！"; 
			    $("#planCostCurrentYear"+id).rules("add", optionRule10);
    		} else {
    			$('#planprojectfee').show();
	    		for(var i=0;i<nameArray.length;i++) {
	    			var name = nameArray[i];
	    			if(name!='') {
	    				var tr = document.createElement("tr");
				    	$(tr).attr("class","listviewTR planprojectfee");
				    	var html = "<td class=\"listviewTD\" align=\"center\">"+name+"</td>";
				    	html += "<td class=\"listviewContent\" ><input type=\"text\" onblur=\"sumTotalCost()\"   datarule=\"number\"    datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"1\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\""+name+"计划总费用\"}'    onblur=\"this.value=this.value.trim()\" id=totalCost"+idArray[i]+" name=\"fieldMap['planProjectMap'].planProjectMap['"+idArray[i]+"'].totalCost\" value=\""+planProjectMap[idArray[i]]['totalCost']+"\" class=\"text totalCostText\" style=\"width:100px;\" ></input></td>";
				    	html += "<td class=\"listviewTD\" ><input type=\"text\" onblur=\"sumPlanCost()\"  datarule=\"number\"    datarulejson='{\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"0\",\"description\":\"8位正数，6位精度的浮点数\",\"length\":\"8\",\"displayName\":\""+name+"当年计划安排费用\"}'    onblur=\"this.value=this.value.trim()\" id=planCostCurrentYear"+idArray[i]+" name=\"fieldMap['planProjectMap'].planProjectMap['"+idArray[i]+"'].planCostCurrentYear\" value=\""+planProjectMap[idArray[i]]['planCostCurrentYear']+"\" class=\"text planCostText\" style=\"width:100px;\" ></input></td>";
				    	html += "<td class=\"listviewContent\" colspan=\"3\">0</td>";
				    	$(tr).html(html);
				    	$(tr).insertAfter(before);
				    	before = $(tr);
	    			}
	    		}
	    		var sumTr = document.createElement("tr");
		    	$(sumTr).attr("class","listviewTR planprojectfee");
		    	var sumHtml = "<td class=\"listviewTD\" align=\"center\">合计</td>";
		    	sumHtml += "<td class=\"listviewContent\" ><label id=\"totalCostSum\">0</label></td>";
		    	sumHtml += "<td class=\"listviewTD\" ><label id=\"planCostSum\">0</label></td>";
		    	sumHtml += "<td class=\"listviewContent\" colspan=\"3\">0</td>";
		    	$(sumTr).html(sumHtml);
		    	$(sumTr).insertAfter(before);
	    		validatorForm();
	    		sumTotalCost();
	    		sumPlanCost();
	    		for(var i=0;i<nameArray.length;i++) {
	    			var name = nameArray[i];
	    			if(name!='') {
				    	var optionRule10 = {};
							var optionRuleMessages10 = {};        
				    	optionRule10["messages"] = optionRuleMessages10;
				      optionRule10["compareLessNumber"] = "#totalCost"+idArray[i];				
				      optionRuleMessages10["compareLessNumber"] = name+"当年计划安排费用应该小于等于"+name+"计划总费用！"; 
					    $("#planCostCurrentYear"+idArray[i]).rules("add", optionRule10);
	    			}
	    		}
    		}
    	}
	}
	</#if>
	
	function sumTotalCost() {
		var sum = new Number(0);
		$('.totalCostText').each(function(){
			if(new Number(this.value)>=0 && new Number(this.value)!=NaN) {
			sum = floatAdd(sum,new Number(this.value));
			}
		});
		$('#totalCostSum').html(sum);
	}
	
	function sumPlanCost() {
		var sum = new Number(0);
		$('.planCostText').each(function(){
			if(new Number(this.value)>=0 && new Number(this.value)!=NaN) {
			sum = floatAdd(sum,new Number(this.value));
			}
		});
		$('#planCostSum').html(sum);
	}
	
</script>

<tr id="planprojectfee" <#if !batchEditProjectList??>style="display:none;"</#if> class="listviewTR">
			<td class="listviewTD" align="center">承担单位</td>
			<td class="listviewContent"><span class="placeholder fontRed">*</span>计划总费用（万元）</td>
			<td class="listviewTD">当年计划安排费用（万元）</td>
			<td class="listviewContent" colspan="3">已拨付费用（万元）</td>
</tr>
<#if batchEditProjectList??>
	<#list batchEditProjectList as project>
		<tr class="listviewTR planprojectfee">
			<td class="listviewTD" align="center">${project.implCompany.name}</td>
			<td class="listviewContent">
				<input type="text" onblur="sumTotalCost()"   datarule="number"    datarulejson='{"dataType":"number","precision":"6","isRequired":"1","description":"8位正数，6位精度的浮点数","length":"8","displayName":"${project.implCompany.name}计划总费用"}'   onblur="this.value=this.value.trim()" id="totalCost${project.implCompany.id?c}" name="fieldMap['planProjectMap'].planProjectMap['${project.implCompany.id?c}'].totalCost" value="<#if project.totalCost??>${project.totalCost?c}</#if>" class="text totalCostText" style="width:100px;" ></input>
			</td>
			<td class="listviewTD">
				<input type="text" onblur="sumPlanCost()"   datarule="number"    datarulejson='{"dataType":"number","precision":"6","isRequired":"0","description":"8位正数，6位精度的浮点数","length":"8","displayName":"${project.implCompany.name}当年计划安排费用"}'   onblur="this.value=this.value.trim()" id="planCostCurrentYear${project.implCompany.id?c}" name="fieldMap['planProjectMap'].planProjectMap['${project.implCompany.id?c}'].planCostCurrentYear" value="<#if project.planCostCurrentYear??>${project.planCostCurrentYear}</#if>" class="text planCostText" style="width:100px;" ></input>
			</td>
			<td class="listviewContent" colspan="3">0</td>
		</tr>
	</#list>
	<#if batchEditProjectList?size gt 0>
		<td class="listviewTD" align="center">合计</td>
		<td class="listviewContent" ><label id="totalCostSum">0</label></td>
		<td class="listviewTD" ><label id="planCostSum">0</label></td>
		<td class="listviewContent" colspan="3">0</td>
	</#if>
</#if>